package com.sunfeng.a03;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author : 孙峰
 * @Description:
 * @Date : 2022/4/8  14:02
 */
@Slf4j
public class TestMethodTemplate {
    public static void main(String[] args) {
        MyBeanFactory myBeanFactory = new MyBeanFactory();
        myBeanFactory.addPostProcessors(bean -> log.info("后置处理器 解析 @Autowired"));
        myBeanFactory.addPostProcessors(bean -> log.info("后置处理器 解析 @Resource"));
        myBeanFactory.getBean();

    }
    static class MyBeanFactory{
        public Object getBean(){
            Object bean = new Object();
            log.info("构造》》{}",bean);
            log.info("依赖注入》》{}",bean);
            for (BeanPostProcessor processor : postProcessors) {
                processor.inject(bean);
            }
            log.info("初始化》》{}",bean);
            return bean;
        }
        private List<BeanPostProcessor> postProcessors=new ArrayList<>();
        public  void  addPostProcessors(BeanPostProcessor beanPostProcessor){
            postProcessors.add(beanPostProcessor);
        }
    }
    static  interface  BeanPostProcessor{
        /**
         * 对依赖注入阶段的扩展
         */
        public  void inject(Object bean);
    }
}
